home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / STANDALO / SHOWINIT / TEST.C < prev   
C/C++ Source or Header  |  1990-07-29  |  3KB  |  115 lines

  1. /*
  2.     init test.c : Entry point for INIT
  3. */
  4. /*
  5.     Notes:
  6.         This stuff is LightSpeed C specific. Other compilers don't allow
  7.             globals in INITs or CODE resources. Remove globals & A4 reference
  8.             for other compilers.
  9.         Set File type to 'INIT' and put in System Folder.
  10.         Use ResEdit or LSC to lock the 'INIT' resource.
  11.         Use ResEdit or LSC to set the System Heap bit.
  12.         Call DetachResource if we want to stay in memory.  See the
  13.             Tech Notes for details on allocating storage space.  Inside
  14.             Mac V has a new way for keeping us around too. I think we'd
  15.             have to set the SYS bit of our resource too.
  16.         Stealing a trap and pointing it to our routine works ok. 
  17.         Globals are passed in as a0 on startup.  CODE resources use globals from
  18.             A4, so we set A4 to point to globals and restore it when done.
  19.             (LSC handles everything else).  LSC 3.0 has new macros for 
  20.             initializing A4. See <SetUpA4.h>. The macros work as follows:
  21.                 __GetA4()         - Puts address of 4 bytes of storage
  22.                                  into A1 (static function).
  23.                 RememberA0()         - A0 -> Storage
  24.                 RememberA4()         - A4 -> Storage
  25.                 SetUpA4()        - Push A4, Storage -> A4
  26.                 RestoreA4()        - Pop A4
  27.         We must initialize toolbox. The only hard one is QuickDraw, since
  28.             thePort isn't correct here. We╒ll allocate a record of size
  29.             GrafSize and pass the address of the last field (thePort) to
  30.              InitGraf.
  31.         Initializing the Window Manager will erase the screen. This would prevent
  32.             us from showing an INIT icon (we'd clear other icons). A #define
  33.             controls this.
  34.             
  35. */
  36.  
  37.  
  38. #include "init.h"
  39.  
  40.  
  41. #ifndef APPLICATION
  42. static QD_GLOBALS our_qd;
  43. #endif
  44.  
  45. void main()
  46. {
  47.     Handle    self_handle;        /* a handle to our own code resource */
  48.     
  49. #ifndef APPLICATION
  50.     CODE_SETUP();            /* push registers to stack, setup A4 */
  51.     
  52.         /* be 100% sure we're locked down. See LSC 3.0 manual p.86 */
  53.     asm
  54.         {
  55.         _RecoverHandle                ;A0 already set up
  56.         move.l a0, self_handle            ;
  57.         }
  58.     HLock(self_handle);
  59. #ifdef PERMANENT
  60.     DetachResource(self_handle);        /* so we'll stay after file closed */
  61. #endif /* PERMANENT */
  62. #endif /* APPLICATION */
  63.  
  64.     init_mac();                /* initialize toolbox */
  65.  
  66. #ifndef APPLICATION
  67.     show_init_icon(300, -1);        /* put the icon on the screen */    
  68. #endif
  69.         load_it();            /* steal the trap */
  70.             /* other trap patches go here */
  71.         unload_it();
  72. #ifndef APPLICATION
  73.     CODE_CLEANUP();            /* restore the registers */
  74. #endif
  75. }
  76.  
  77.  
  78.  
  79. /*
  80.     init_mac : Initializes Mac toolbox
  81.     
  82.         Note:
  83.             Initialization depends on APPLICATION and INIT_ALL #defines
  84.             If not an application, INIT_ALL #define means to
  85.                 initialize all toolbox managers. This will erase
  86.                 the screen, though.
  87. */
  88. init_mac()
  89. {
  90. #ifdef APPLICATION
  91.     InitGraf(&thePort);
  92.     InitFonts();
  93.     InitWindows();
  94.     InitCursor();
  95.     InitMenus();
  96.     InitDialogs (0L);
  97.     TEInit();
  98. #else
  99.     InitGraf(&our_qd.thePort);
  100. #ifdef INIT_ALL
  101.     DeskHook = 0;
  102.     DragHook = 0;
  103.     InitFonts();
  104.     InitWindows();
  105.     InitCursor();
  106.     InitMenus();
  107.     InitDialogs(NULL);
  108.     TEInit();
  109. #endif    /* INIT_ALL */
  110. #endif    /* not APPLICATION */
  111.     FlushEvents(everyEvent, 0);
  112. }
  113.  
  114.  
  115.